package thread_pool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolExecutorTest {
    public static void main(String[] args){

        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                3,  //核心线程数量
                6,  //最大线程数
                60,    //空闲最大存活时间
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(3),  // 任务队列
                Executors.defaultThreadFactory(),     //创建线程工厂
                new ThreadPoolExecutor.AbortPolicy()  //任务的拒绝策略
        );
        threadPoolExecutor.submit(new MyRunnable());
        threadPoolExecutor.submit(new MyRunnable());
        threadPoolExecutor.submit(new MyRunnable());

        threadPoolExecutor.submit(new MyRunnable());
        threadPoolExecutor.submit(new MyRunnable());
        threadPoolExecutor.submit(new MyRunnable());

        threadPoolExecutor.submit(new MyRunnable());
        threadPoolExecutor.submit(new MyRunnable());
        threadPoolExecutor.submit(new MyRunnable());

        threadPoolExecutor.shutdown();
    }
}
